#ifndef TCPACCEPTOR_H
#define TCPACCEPTOR_H

#include "../global.h"
#include <boost/asio.hpp>
#include <boost/function.hpp>

class TcpAcceptor : protected boost::noncopyable
{
public:
    typedef boost::asio::io_service Implement;
    typedef boost::asio::ip::tcp::acceptor Acceptor;
    typedef boost::asio::ip::tcp::socket Socket;
    typedef boost::asio::ip::tcp::endpoint Endpoint;
    typedef boost::asio::ip::address Address;
    typedef boost::system::error_code ErrorCode;

    typedef boost::function< void (int) > Notifier;

public:
    TcpAcceptor(Implement &impl);
    ~TcpAcceptor();

    int  open(const std::string &host, unsigned short port, int listenCount);

    void close();

    void accept(Socket &sock, BOOST_ASIO_MOVE_ARG(Notifier) n);

protected:
    void onAccepted(Notifier n, ErrorCode ec);

protected:
    Acceptor m_acceptor;
};

#endif // TCPACCEPTOR_H
